package com.ihd.ihardware.view.lock.viewmodel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.databinding.ObservableArrayList;
import android.support.annotation.NonNull;

import com.ihd.ihardware.R;
import com.ihd.ihardware.databinding.ItemLockHisBinding;
import com.ihd.ihardware.pojo.DeviceListRes;
import com.ihd.ihardware.view.lock.model.LockRepository;

import java.util.List;

import cn.wowjoy.commonlibrary.adapter.CommonAdapter;

public class LockRecoViewModel extends AndroidViewModel {

    private LockRepository mLockRepository;

    public LockRecoViewModel(@NonNull Application application) {
        super(application);
    }

    public void lockRecordList(String equipmentId) {
        if (mLockRepository == null)
            mLockRepository = new LockRepository();
        mLockRepository.lockRecordList(equipmentId);
    }

    private ObservableArrayList<DeviceListRes.DataBean.ListBean> mLockHis = new ObservableArrayList<>();
    public CommonAdapter mLockHisAdapter = new CommonAdapter<DeviceListRes.DataBean.ListBean, ItemLockHisBinding>(R.layout.item_lock_his, mLockHis, null) {
        @Override
        public void convert(ItemLockHisBinding mDataBinding, DeviceListRes.DataBean.ListBean tza, int position) {
        }
    };

    public void setLockHis(List<DeviceListRes.DataBean.ListBean> list) {
        mLockHis.clear();
        if (list != null && list.size() > 0)
            mLockHis.addAll(list);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if (null != mLockRepository) {
            mLockRepository.onDestroy();
            mLockRepository = null;
        }
    }
}
